package com.bristua.barcode.supplier.biz;

import com.bristua.barcode.common.bean.PageBean;
import com.bristua.barcode.supplier.dao.TSupplierMapper;
import com.bristua.barcode.supplier.model.TSupplier;
import com.bristua.barcode.supplier.model.condition.QuerySupplierParams;
import com.bristua.barcode.supplier.model.condition.TSupplierExample;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2019/8/6 0006.
 */
@Service
public class QuerySupplierBiz {
    @Resource
    private TSupplierMapper tSupplierMapper;

    public PageBean<TSupplier> querySupplier(QuerySupplierParams querySupplierParams){

        TSupplierExample tSupplierExample = new TSupplierExample();

        if(!StringUtils.isEmpty(querySupplierParams.getSupplierName())){
            tSupplierExample.createCriteria().andSupplierNameLike("%"+querySupplierParams.getSupplierName()+"%");
        }

        if(!StringUtils.isEmpty(querySupplierParams.getPhone())){
            tSupplierExample.createCriteria().andPhoneLike("%"+querySupplierParams.getPhone()+"%");
        }

        tSupplierExample.setOrderByClause("create_time desc");

        Page<TSupplier> objects = PageHelper.startPage(querySupplierParams.getPageNo(),querySupplierParams.getPageSize());

        tSupplierMapper.selectByExample(tSupplierExample);

        return new PageBean<>(objects);
    }
}
